package tech.yunjing.train.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import tech.yunjing.train.entity.Account;
import tech.yunjing.train.entity.AccountDetail;
import tech.yunjing.train.service.AccountDetailService;
import tech.yunjing.train.util.JsonResult;

/**
 * 账户明细管理Controller
 * Created by ZhangFan on 2017/6/9.
 */
@RestController
@RequestMapping("/account")
public class AccountDetailController extends BaseController {
    @Autowired
    AccountDetailService accountDetailService;

    /**
     * 增加账户明细
     *
     * @param accountDetail
     * @return AccountDetail账户明细对象
     */
    @RequestMapping(value = "/addAccountDetail", method = RequestMethod.POST)
    public JsonResult<Integer> addAccountDetail(AccountDetail accountDetail) {
        int row = accountDetailService.addAccountDetail(accountDetail);
        return new JsonResult<Integer>(row);
    }

    /**
     *
     * @param accountId 账户id
     * @return  Account对象(包含明细)
     */
    @RequestMapping(value = "/findDetailById", method = RequestMethod.POST)
    public JsonResult<Account> findAccountDetail(Integer accountId) {
        Account account = accountDetailService.findAccountDetailsByAccountId(accountId);
        return new JsonResult<Account>(account);
    }
    /**
     * 根据账户名查询账户明细
     *
     * @param accountName 账户名
     * @return Account对象(包含明细)
     */
    @RequestMapping(value = "/findDetailByName", method = RequestMethod.POST)
    public JsonResult<Account> findAccountDetail(String accountName) {
        Account account = accountDetailService.findAccountDetailsByAccountName(accountName);
        return new JsonResult<Account>(account);
    }

}
